package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.AdminTeacher;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.mapper.AdminTeacherMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.IAdminTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 教师Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-06-09
 */
@Service
public class AdminTeacherServiceImpl implements IAdminTeacherService 
{
    @Autowired
    private AdminTeacherMapper adminTeacherMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询教师
     * 
     * @param teacherId 教师ID
     * @return 教师
     */
    @Override
    public AdminTeacher selectAdminTeacherById(Long teacherId)
    {
        return adminTeacherMapper.selectAdminTeacherById(teacherId);
    }

    /**
     * 查询教师列表
     * 
     * @param adminTeacher 教师
     * @return 教师
     */
    @Override
    public List<AdminTeacher> selectAdminTeacherList(AdminTeacher adminTeacher)
    {
        return adminTeacherMapper.selectAdminTeacherList(adminTeacher);
    }

    /**
     * 新增教师
     * 
     * @param adminTeacher 教师
     * @return 结果
     */
    @Override
    public int insertAdminTeacher(AdminTeacher adminTeacher)
    {
        adminTeacher.setCreateTime(DateUtils.getNowDate());
        return adminTeacherMapper.insertAdminTeacher(adminTeacher);
    }

    /**
     * 修改教师
     * 
     * @param adminTeacher 教师
     * @return 结果
     */
    @Override
    public int updateAdminTeacher(AdminTeacher adminTeacher)
    {
        adminTeacher.setUpdateTime(DateUtils.getNowDate());
        return adminTeacherMapper.updateAdminTeacher(adminTeacher);
    }

    /**
     * 删除教师对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteAdminTeacherByIds(String ids)
    {
        return adminTeacherMapper.deleteAdminTeacherByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除教师信息
     * 
     * @param teacherId 教师ID
     * @return 结果
     */
    @Override
    public int deleteAdminTeacherById(Long teacherId)
    {
        return adminTeacherMapper.deleteAdminTeacherById(teacherId);
    }
    
    /**
     * 教师状态修改
     * 
     * @param adminTeacher 教师信息
     * @return 结果
     */
    @Override
    public int changeStatus(AdminTeacher adminTeacher)
    {
        return adminTeacherMapper.updateAdminTeacher(adminTeacher);
    }

    @Override
    public int insertAdminTeacherAndUser (AdminTeacher adminTeacher, SysUser sysUser) {
      adminTeacher.setCreateTime(DateUtils.getNowDate());
      adminTeacherMapper.insertAdminTeacher(adminTeacher);
      sysUser.setUserType(UserConstants.TEACHER_USER_TYPE);
      return sysUserMapper.insertUser(sysUser);
    }
}
